<template>
    <div class="body_background" :style="GetWindowBackground">
        <div class="body_background padding-top10 ">
            <div class="block-box items-start">
                <div class="big-font-size three-color">基础信息</div>
                <ul class="create-box">
                    <li>
                        <div class="big-font-size main-color">计划名称：</div>
                        <div class="three-color">九月盘点</div>
                    </li>
                    <li>
                        <div class="big-font-size main-color">计划编号：</div>
                        <div class="three-color">2646465</div>
                    </li>
                    <li>
                        <div class="big-font-size main-color">创&nbsp;&nbsp;建&nbsp;&nbsp;人：</div>
                        <div class="three-color">创建人</div>
                    </li>
                    <li>
                        <div class="big-font-size main-color">创建时间：</div>
                        <div class="three-color">2021-12-15</div>
                    </li>
                    <li>
                        <div class="big-font-size main-color">备注内容：</div>
                        <div class="three-color">备注内容</div>
                    </li>
                </ul>
            </div>
            <div class="block-box items-start order-list-box">
                <div class="big-font-size three-color">盘点商品清单（待盘点）</div>
                <div class="order-list-item">
                    <div class="order-content-box" v-for="item in goodsList" :key="item.id">
                        <div class="big-small-circular" :class="item.choseFlag==true?'background':''"
                             @click="choseGoodsFun(item)"
                        >
                            <div class="small-circular" v-if="item.choseFlag==true"></div>
                        </div>
                        <img :src="item.imgUrl"/>
                        <div class="order-info-box">
                            <div class="main-color big-font-size">商品名称</div>
                            <div class="goods-content">
                                <div>
                                    <div class="three-color small-font-size">分类：蔬菜</div>
                                    <div class="three-color small-font-size">规格：200g</div>
                                    <div class="three-color small-font-size">库存：200袋</div>
                                    <div class="three-color small-font-size">货值：￥2020</div>
                                </div>
                                <!--购物车加减号-->
                                <div class="shop-cart-box">
                                    <div class="shop-cart-button green-color"
                                         @click="minusGoodsFun(item)"
                                    >-
                                    </div>
                                    <input type="number"
                                           v-model="item.num"
                                           class="shop-cart-input"
                                           @blur="inputBlurFun(item,item.num)"
                                    />
                                    <div class="shop-cart-button background"
                                         @click="addGoodsFun(item,false)"
                                    >+
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="block-box items-start marBottom">
            <div class="big-font-size main-color">备注</div>
            <textarea class="note-content" placeholder="请输入备注" v-model="note"></textarea>
        </div>
        <div class="body_background create-button-box">
            <mt-button class="width40 middle-font-size"
                       @click="cancelClickFun"
            >取消
            </mt-button>
            <mt-button class="width40 middle-font-size background white-color"
                       @click="createInventoryFun"
            >提交
            </mt-button>
        </div>
    </div>
</template>

<script>
    import {Toast} from 'mint-ui';

    export default {
        name: "StockInventorySub",
        data() {
            return {
                GetWindowBackground: {
                    'min-height': ''
                },
                goodsList: [],
                note:'',

            }
        },
        mounted() {
            this.getNewGoodsList();//重新整合商品数据
        },
        methods: {
            //重新整合商品数据
            getNewGoodsList() {
                var list = [
                    {
                        id: 1,
                        title: "秘制小番茄500g",
                        spec: '500g/袋',
                        weight: '500g',
                        num: 12,
                        imgUrl:
                            "https://t00img-c.yangkeduo.com/goods/images/2020-08-13/ce99a1b2f665ba478d9573c314686c5d.jpeg"
                    },
                    {
                        id: 2,
                        title: "秘制小龙虾1500g",
                        spec: '500g/袋',
                        weight: '500g',
                        num: 1,
                        imgUrl:
                            "https://t00img-c.yangkeduo.com/goods/images/2020-08-13/ce99a1b2f665ba478d9573c314686c5d.jpeg"
                    },
                ];
                for (var i = 0; i < list.length; i++) {
                    var item = list[i]
                    item['choseFlag'] = item.num > 0 ? true : false;
                }
                this.goodsList = list
            },
            //选商品
            choseGoodsFun(item) {
                item.choseFlag = !item.choseFlag
                item.num = item.choseFlag == true ? 1 : 0
            },

            //input失焦时间（商品数量填写失焦）
            inputBlurFun(item, num) {
                this.addGoodsFun(item, num)
            },

            //选商品
            minusGoodsFun(item) {
                if (item.num <= 0) {
                    Toast('不能再减啦')
                    return false
                }
                if (item.num == 1) {
                    item.choseFlag = false
                    item.num = --item.num
                } else {
                    item.num = --item.num
                }
            },

            //选商品
            addGoodsFun(item, num) {
                console.log(num)
                item.num = num == false ? ++item.num : Number(num)
                item.choseFlag = true
            },

            //取消
            cancelClickFun() {
                Toast('取消');
            },
            //提交
            createInventoryFun() {
                var list = this.goodsList;
                var arr = [];
                for (var i = 0; i < list.length; i++) {
                    let item = list[i]
                    if (item.choseFlag) {
                        arr.push({
                            id: item.id,
                            num: item.num
                        })
                    }
                }
                var data={
                    arr:arr,
                    note:this.note
                }
                console.log(data)
                return
                this.$router.push('/StockInventoryList')
            },

            getHeight() {
                // 获取浏览器高度
                this.GetWindowBackground['min-height'] = window.innerHeight + 'px'
            },
        },
        // 生命周期 - 创建完成（可以访问当前this实例）
        created() {
            window.addEventListener('resize', this.getHeight) // 注册监听器
            this.getHeight() // 页面创建时先调用一次
        },
        // 生命周期 - 销毁完成
        destroyed() {
            window.removeEventListener('resize', this.getHeight)
        },
    }
</script>

<style lang="scss" scoped>

    .create-box {
        width: 100%;
        margin-top: 5px;
        li {
            width: 100%;
            height: 45px;
            display: flex;
            align-items: flex-end;
            div {
                margin-bottom: 7px;
            }
        }
    }

    .order-list-box {
        margin: 10px auto;
        .order-list-item {
            width: 100%;
            background: #fff;
            margin-top: 10px;
            border-radius: 4px;
            .order-top-box {
                width: 100%;
                height: 35px;
                display: flex;
                justify-content: space-between;
                align-items: center;
            }
            .order-content-box {
                width: 100%;
                display: flex;
                align-items: center;
                padding: 7px 0;
                img {
                    width: 80px;
                    height: 80px;
                    margin-right: 8px;
                    border-radius: 4px;
                }
                .goods-content {
                    width: 100%;
                    display: flex;
                    justify-content: space-between;
                }
                .order-info-box {
                    width: calc(100% - 110px);
                    position: relative;
                    display: flex;
                    flex-direction: column;
                    justify-content: space-between;
                    text-align: left;
                }
                .goods-count {
                    margin-left: auto;
                    margin-top: 5px;
                }
            }
            .big-small-circular {
                width: 15px;
                height: 15px;
                border-radius: 50%;
                border: 1px solid #05c569;
                display: flex;
                justify-content: center;
                align-items: center;
                margin-right: 10px;
                .small-circular {
                    width: 7px;
                    height: 7px;
                    border-radius: 50%;
                    background: #fff;
                }
            }
        }
    }
    .order-content-div {
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: space-between;
        border-top: 1px dashed #D2D6DC;
        padding-top: 5px;
        margin-top: 15px;
        font-size: 15px;
        .content-item {
            width: 100%;
            min-height: 30px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
    }
    .note-content{
        width: calc(100% - 20px);
        border-radius: 6px;
        border: 1px solid #eef0f3;
        margin-top: 5px;
        text-align: left;
        font-size: 13px;
        padding: 10px;
    }
    .create-button-box {
        width: 100%;
        height: 70px;
        position: fixed;
        bottom: 0px;
        display: flex;
        justify-content: space-around;
        align-items: center;
        .width40 {
            width: 40%;
            border: 1px solid #05c569;
            color: #05c569;
            border-radius: 10px;
        }
    }

    .shop-cart-box {
        position: absolute;
        bottom: 30px;
        right: 0px;
        display: flex;
    }

</style>